package com.test.suanfa;

import java.util.LinkedHashMap;
import java.util.Map;

public class LRU缓存 {

    public static void main(String[] args) {
        LRU1 lru = new LRU1(5);
        for (int i = 0; i < 11; i++) {
            lru.put(i, i);
        }
        System.out.println(lru.entrySet().stream().findFirst());
    }

    static class LRU1 extends LinkedHashMap {

        private int max;

        public LRU1(int max) {
            this.max = max;
        }

        @Override
        protected boolean removeEldestEntry(Map.Entry eldest) {
            return size() > max;
        }
    }
}
